<template>
	<view>
		<view class="search-box">
			<t-search v-model="search" @confirm="$jumpUrl(`/subPages/searchList/searchList?keyword=${search}`)" plac-text="关键词搜一下"></t-search>
		</view>
		<t-tabs :list="tabsList" :activeIndex="tabsIndex" @change="tabsChange"></t-tabs>
		<swiper class="swiper-box">
			<swiper-item class="sw-item" v-for="(item,index) in banner">
				<image @click="bannerClick(item)" :src="`https://www.worldintek.com:39011/yaolexue-service/${item.imageDto.compressLink}`" class="sw-img"></image>
				<view class="cr-333 font_s32 font_w600 padd-left31 line-height100 padd-top4">
					{{item.bannerName}}
				</view>
				<view class="padd-right30 flex justify-end cr-FA312A font_s26 mar-top24 line-height100 sw-number">
					{{index+1}}
				</view>
			</swiper-item>
		</swiper>
		<view class="list">
			<view v-for="(item,index) in list" :key="item.id" class="list-item" @click="clickJump(item)">
				<view class="cr-333 font_s30 line-height100">
					{{item.title}}
				</view>
				<view class="list-item-img">
					<image v-for="(v,k) in item.imageDtos" :key="v" :src="`https://www.worldintek.com:39011/yaolexue-service/${v.compressLink}`"></image>
				</view>
				<view class="font_s26 cr-999 mar-top20 line-height100">
					<text class="">
						{{item.createByName}}
					</text>
					<text class="mar-left14">
						{{item.createTime}}
					</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				search: '',
				tabsList: [],
				tabsIndex: 0,
				page:{
					page:1,
					limit:15
				},
				noMore:false,
				list:[],
				banner:[]
			};
		},
		async onLoad() {
			this.getBanner()
			await this.getTabsList()
			this.tabsList.length && this.getList()
		},
		onReachBottom() {
			if(!this.noMore)
				this.getList()
		},
		methods: {
			getTabsList() {
				return this.$http.get('/yaolexue-service-portal/column/columnAll/1', {
				}).then(res => {
          console.log('getTabsList', res);
					if (res.code == 200) {
						this.tabsList = res.data
						console.log(this.tabsList,'==>this.tabsList')
					}
				})
			},
			getBanner(){
				return this.$http.get(
					`/yaolexue-service-portal/contentItem/findHomeBannerBoardByPosition/3`, {}, {
						isNeedLoading: false
					}).then(res=>{
						console.log(res,2222)
						this.banner=res.data
					})
			},
			getList(){
				this.$http.get(`/yaolexue-service-portal/contentItem/pageContentImageText`,{
					columnNavId:this.tabsList[this.tabsIndex].id,
					title:this.search,
					...this.page
				}).then(res => {
					if(res.code == 200){
						if(this.page.page == 1) this.list = []
						this.list = [...this.list,...res.data.items]
						this.noMore = this.list.length >= res.data.total
						this.page.page++
					}
				})
			},
			clickJump(item){
				uni.navigateTo({
					url:`/pages/imgtxtDetails/imgtxtDetails?id=${item.id}`
				})
			},
			tabsChange(e) {
				this.tabsIndex = e
				this.page.page = 1
				this.noMore = false
				this.getList()
			},
			searchConfirm(){
				this.page.page = 1
				this.noMore = false
				this.getList()
			},
      bannerClick(item) {
       
        let url = ''
        switch (item.contentItemType) {
        	case 1:
        		url = `/pages/imgtxtDetails/imgtxtDetails?id=${item.contentItemId}`
        		break;
        	case 2:
        		url = `/pages/VideoItemDetail/VideoItemDetail?id=${item.contentItemId}`
        		break;
        	case 3:
        		url = `/pages/AudioItemList/AudioItemList?id=${item.albumId}&cid=${item.contentItemId}`
        		break;
        	default:
        		break;
        }
       uni.navigateTo({
         url
       })
       
      },
		}
	}
</script>

<style lang="scss" scoped>
	.search-box {
		width: 100%;
		height: 145rpx;
		background: #FA312A;
		display: flex;
		justify-content: center;
		align-items: center;
	}



	.swiper-box {
		width: 100%;
		height: 450rpx;
		background: #FAFAFA;

		.sw-item {
			width: 100%;
			height: 100%;

			.sw-img {
				width: 100%;
				height: 340rpx;
			}

			.sw-number {
				position: relatie;
				display: inline-flex;
				align-items: center;
				float: right;

				&::before {
					content: '';
					width: 45rpx;
					height: 2rpx;
					background: #E1E1E1;
					display: inline-block;
					margin-right: 21rpx;
				}

				&::after {
					content: '';
					width: 45rpx;
					height: 2rpx;
					background: #E1E1E1;
					display: inline-block;
					margin-left: 21rpx;
				}
			}
		}
	}

	.list {
		background: #fff;
		padding: 0 30rpx;

		.list-item {
			padding: 29rpx 0 27rpx 0;
			border-bottom: 1px solid RGBA(240, 240, 240, 0.3);

			.list-item-img {
				margin-top: 19rpx;

				image {
					width: 220rpx;
					height: 130rpx;
					border-radius: 10rpx;

					&:not(:nth-child(3n)) {
						margin-right: 14rpx;
					}
				}
			}
		}
	}
</style>